
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>浏览页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
        <link rel="stylesheet" href="../../demos/css/console2.css" />
        <style>

            .pear-card2 .title {
                color: gray;
                font-size: 16px;
                margin-top: 14px;
            }
            .pear-this, .pear-text {
                color: #2d8cf0 !important;
                font-size: 18px;
            }
        </style>
    </head>
    <body class="pear-container">
    
        <!-- 顶部查询表单 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form top-search-from">
                    <div class="layui-form-item">
                        <label class="layui-form-label">订单号</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="order_no" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户编号</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="user_sn" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">交易号</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="trade_no" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">购买类型</label>
                        <div class="layui-input-block">
                            <div name="product_type" id="product_type" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付渠道</label>
                        <div class="layui-input-block">
                            <div name="payment" id="payment" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">订单状态</label>
                        <div class="layui-input-block">
                            <div name="order_status" id="order_status" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否续订</label>
                        <div class="layui-input-block">
                            <div name="isrenew" id="isrenew" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">新用户充值</label>
                        <div class="layui-input-block">
                            <div name="is_new_user_recharge" id="is_new_user_recharge" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">巨量推广</label>
                        <div class="layui-input-block">
                            <div name="is_oceanengine_promotion_user" id="is_oceanengine_promotion_user" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block" id="pay_time">
                                <input type="text" autocomplete="off" name="pay_time[]" id="pay_time-date-start" class="layui-input inline-block" placeholder="开始时间">
                                -
                                <input type="text" autocomplete="off" name="pay_time[]" id="pay_time-date-end" class="layui-input inline-block" placeholder="结束时间">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block" id="created_at">
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-start" class="layui-input inline-block" placeholder="开始时间">
                                -
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-end" class="layui-input inline-block" placeholder="结束时间">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label"></label>
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md" lay-submit lay-filter="table-reset">
                            <i class="layui-icon layui-icon-refresh"></i>重置
                        </button>
                    </div>
                    <div class="toggle-btn">
                        <a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
                        <a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
                    </div>
                </form>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-header">
                订单统计
            </div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">累计订单金额</div>
                            <div class="total_order_amount pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">累计订单数</div>
                            <div class="total_order_nums pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">开通会员订单金额</div>
                            <div class="total_vip_order_amount pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">开通会员订单数</div>
                            <div class="total_vip_order_nums pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">购买点数订单金额</div>
                            <div class="total_buy_order_amount pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">购买点数订单数</div>
                            <div class="total_buy_order_nums pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">累计订单人数</div>
                            <div class="total_order_user_peoples pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">新用户充值比例</div>
                            <div class="new_user_recharge_ratio pear-text">0</div>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm6 layui-col-xs6">
                        <div class="pear-card2">
                            <div class="title">老用户充值比例</div>
                            <div class="old_user_recharge_ratio pear-text">0</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 数据表格 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="data-table" lay-filter="data-table"></table>
            </div>
        </div>

        <!-- 表格顶部工具栏 -->
        <!--<script type="text/html" id="table-toolbar">-->
            <!--<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.font.index.insert">-->
                <!--<i class="layui-icon layui-icon-add-1"></i>新增-->
            <!--</button>-->
            <!--<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.font.index.delete">-->
                <!--<i class="layui-icon layui-icon-delete"></i>删除-->
            <!--</button>-->
        <!--</script>-->

        <!-- 表格行工具栏 -->
        <!--<script type="text/html" id="table-bar">-->
            <!--<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.font.index.update">编辑</button>-->
            <!--<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.font.index.delete">删除</button>-->
        <!--</script>-->

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/common.js"></script>
        <script src="/app/admin/admin/js/functions.js"></script>
        <script src="/app/admin/admin/js/md5.js"></script>
        
        <script>

            // 相关常量
            const PRIMARY_KEY = "id";
            const SELECT_API = "/app/admin/order/index/select";

            let where = {};
            let isHide =false;

            // 字段 添加时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#created_at",
                    range: ["#created_at-date-start", "#created_at-date-end"],
                    type: "datetime",
                    mark: date_today_mark,
                });
            })

            // 字段 添加时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#pay_time",
                    range: ["#pay_time-date-start", "#pay_time-date-end"],
                    type: "datetime",
                    mark: date_today_mark,
                });
            })

            // 字段 状态 product_type
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#product_type",
                    name: "product_type",
                    filterable: true,
                    initValue: [],
                    data: [{"value":"1","name":"开通会员"},{"value":"2","name":"购买点数"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });
            // 字段 状态 payment
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#payment",
                    name: "payment",
                    filterable: true,
                    initValue: [],
                    data: [{"value":"1","name":"IOS"},{"value":"3","name":"微信"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });
            // 字段 状态 order_status
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#order_status",
                    name: "order_status",
                    filterable: true,
                    initValue: [],
                    data: [{"value":"1","name":"待支付"},{"value":"3","name":"支付失败"},{"value":"6","name":"支付成功"},{"value":"7","name":"已退款"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });

            // 字段 状态 isrenew
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#isrenew",
                    name: "isrenew",
                    filterable: true,
                    initValue: [],
                    data: [{"value":"1","name":"是"},{"value":"0","name":"否"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });

            // 字段 新用户充值 is_new_user_recharge
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#is_new_user_recharge",
                    name: "is_new_user_recharge",
                    filterable: true,
                    initValue: [],
                    data: [{"value":"1","name":"是"},{"value":"0","name":"否"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });

            // 字段 巨量推广用户 is_oceanengine_promotion_user
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#is_oceanengine_promotion_user",
                    name: "is_oceanengine_promotion_user",
                    filterable: true,
                    initValue: [],
                    data: [{"value":"1","name":"是"},{"value":"0","name":"否"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true
                })
            });

            // 表格渲染
            layui.use(["table", "form", "common", "popup", "util"], function() {
                let table = layui.table;
                let form = layui.form;
                $ = layui.$;
                let common = layui.common;
                let util = layui.util;
                
				// 表头参数
				let cols = [
					{
						title: "订单编号",align: "center", field: "order_no",width:130,sort:true,
					},{
						title: "用户编号",align: "center", field: "user_sn",width:120,sort:true,
					},{
						title: "用户昵称",align: "center", field: "nickname",width:150,sort:true,
					},{
						title: "购买类型",align: "center", field: "product_type",width:110,sort:true, templet: function (d) {
						    if(d.product_type==1){
                                return '<span style="color: #c50ecf">开通会员</span>';
                            }else{
                                return '<span style="color: #13b162">购买点数</span>';
                            }
                        }
					},{
                        title: "新用户充值",align: "center", field: "is_new_user_recharge",width: 120,sort:true, templet: function (d) {
                            if(d.is_new_user_recharge==1){
                                return '<span style="color: dodgerblue">是</span>';
                            }else{
                                return '<span style="color: #b3aead">否</span>';
                            }
                        }
                    },{
                        title: "巨量推广",align: "center", field: "is_oceanengine_promotion_user",width: 120,sort:true, templet: function (d) {
                            if(d.is_oceanengine_promotion_user==1){
                                return '<span style="color: dodgerblue">是</span>';
                            }else{
                                return '<span style="color: #b3aead">否</span>';
                            }
                        }
                    },{
                        title: "订单金额",align: "center", field: "money",width: 120,sort:true,
                    },{
                        title: "点数",align: "center", field: "point_nums",width: 120,sort:true,
                    },{
                        title: "支付时间",align: "center", field: "pay_time",width: 160,sort:true,
                    },{
						title: "订单状态",align: "center", field: "order_status",width:120,sort:true, templet: function (d) {
                            if(d.order_status==1){
                                return '<span style="color: #c50ecf">待支付</span>';
                            }else if(d.order_status==2){
                                return '<span style="color: #13b162">支付成功，取消订阅</span>';
                            }else if(d.order_status==3){
                                return '<span style="color: #13b162">支付失败</span>';
                            }else if(d.order_status==6){
                                return  '<span style="color: #234be3">支付成功</span>';
                            }else if(d.order_status==7){
                                return  '<span style="color: #999999">已退款</span>';
                            }
						}
					},{
                        title: "支付渠道",align: "center", field: "payment",width: 120,sort:true, templet: function (d) {
                            if(d.payment==1){
                                return '<span style="color: #c50ecf">IOS</span>';
                            }else if(d.payment==3){
                                return '<span style="color: #13b162">微信</span>';
                            }
                        }
                    },{
                        title: "产品ID",align: "center", field: "product_id",width: 100,
                    },{
                        title: "有效期",align: "center", field: "expires_date",width: 160,sort:true,
                    },{
                        title: "是否续订",align: "center", field: "isrenew",width: 120,sort:true, templet: function (d) {
                            if(d.isrenew==1){
                                return '<span style="color: dodgerblue">是</span>';
                            }else{
                                return '<span style="color: #b3aead">否</span>';
                            }
                        }
                    },{
                        title: "交易号",align: "center", field: "trade_no",width:150,sort:true
                    },{
                        title: "原始交易号",align: "center", field: "original_trade_no",width:150,sort:true
                    },{
                        title: "添加时间",align: "center", field: "created_at",width: 160,sort:true,
                    }
				];
				
				// 渲染表格
				table.render({
				    elem: "#data-table",
				    url: SELECT_API,
				    page: true,
                    limit: 10, // 默认每页显示的数量
                    limits: [10, 20, 50, 100, 500, 1000], // 每页条数的选择项
                    headers: get_header(where),
				    cols: [cols],
				    skin: "line",
				    size: "lg",
				    toolbar: "#table-toolbar",
				    autoSort: false,
				    defaultToolbar: [{
				        title: "刷新",
				        layEvent: "refresh",
				        icon: "layui-icon-refresh",
				    }, "filter", "print", "exports"],
				    done: function (res) {
				        layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
                        var data  = res.total_data;
                        $.each(data,function (i,v) {
                            $('.'+i).text(v);
                        })
				    }
				});

                // 表格顶部搜索事件
                form.on("submit(table-query)", function(data) {
                    where = searchWhere(data.field);
                    table.reload("data-table", {
                        page: {
                            curr: 1
                        },
                        where: where,
                        headers: get_header(where)
                    })
                    return false;
                });
                
                // 表格顶部搜索重置事件
                form.on("submit(table-reset)", function(data) {
                    where = {};
                    table.reload("data-table", {
                        where: where,
                        headers: get_header(where)
                    })
                });

                // 表格排序事件
                table.on("sort(data-table)", function(obj){
                    where.field=obj.field;
                    where.order=obj.type;
                    table.reload("data-table", {
                        initSort: obj,
                        scrollPos: "fixed",
                        where: where,
                        headers: get_header(where)
                    });
                });


                // 刷新表格数据
                window.refreshTable = function(param) {
                    table.reloadData("data-table", {
                        scrollPos: "fixed"
                    });
                }
            })

        </script>
    </body>
</html>
